import java.util.Scanner;

public class Tree {
    class TreeNode {
        private TreeNode node;
        private char val;
        //左右
        private TreeNode left;
        private TreeNode right;
        public TreeNode(char val) {
            this.val = val;
        }
    }

    //使用前序遍历构造二叉树
    private int i=0;
    public TreeNode create(String str){
        TreeNode root=null;
        if(str.charAt(i)!='#'){
            root=new TreeNode(str.charAt(i));
            i++;
            root.left=create(str);
            root.right=create(str);
        }else{
            //为‘#’时走这里，然后把null返回去
            i++;
        }
        //无论是new一个对象还是null都会返回去，拼接left或者right
        return root;
    }

    //中序遍历 输出
    public void fun(TreeNode root){
        if(root==null){
            return;
        }
        fun(root.left);
        System.out.print(root.val+" ");
        fun(root.right);
    }

    public static void main(String[] args) {
        Tree tree=new Tree();
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            String str=scanner.nextLine();
            tree.fun(tree.create(str));
        }

    }

}


